from datetime import datetime , timedelta
class TUtilsTime:
    def __init__(self):
        pass
    @staticmethod
    def utc2local(utcTime):
        res = ""
        try:
            localTm = datetime.strptime(utcTime, "%Y-%m-%dT%H:%M:%SZ") + timedelta(hours=8)
            res = localTm.strftime("%Y-%m-%d %H:%M:%S")
        except Exception as er:
            print(er)
        return  res
    @staticmethod
    def local2Utc(localTime):
        res = ""
        try:
            localTm = datetime.strptime(localTime, "%Y-%m-%d %H:%M:%S") + timedelta(hours=-8)
            res = localTm.strftime("%Y-%m-%dT%H:%M:%SZ")
        except Exception as er:
            print(er)
        return  res
    @staticmethod
    def time2Utc(dt):
        res = ""
        try:
            res  = (dt + timedelta(hours=-8)).strftime("%Y-%m-%dT%H:%M:%SZ")
        except Exception as er:
            print(er)
        return  res
    @staticmethod
    def time2Local(dt):
        res = ""
        try:
            res  = dt.strftime("%Y-%m-%dT%H:%M:%SZ")
        except Exception as er:
            print(er)
        return  res
    @staticmethod
    def getTimes(timeKey , timeFormat="%Y%m%d%H%M%S"):
        res = {
            "dt":None,
            "strUtc":"",
            "strLocal":""
        }
        try:
            dt = datetime.strptime(timeKey , timeFormat)
            strLocal  = dt.strftime("%Y-%m-%d %H:%M:%S")
            strUtc  = (dt + timedelta(hours=-8)).strftime("%Y-%m-%dT%H:%M:%SZ")
            res = {
                "dt":dt,
                "strUtc":strLocal,
                "strLocal":strUtc
            }
        except Exception as er:
            print(er)
        return  res